

package com.hazelcast.test.starter.constructor;

import com.hazelcast.test.starter.HazelcastStarterConstructor;

import static com.hazelcast.test.starter.ReflectionUtils.setFieldValueReflectively;

@HazelcastStarterConstructor(classNames = {"com.hazelcast.config.CacheConfig", "com.hazelcast.cache.impl.PreJoinCacheConfig"})
public class CacheConfigConstructor extends AbstractConfigConstructor {

    public CacheConfigConstructor(Class<?> targetClass) {
        super(targetClass);
    }

    @Override
    Object createNew0(Object delegate) throws Exception {
        ClassLoader classloader = targetClass.getClassLoader();
        Object otherConfig = cloneConfig(delegate, classloader);
        setFieldValueReflectively(otherConfig, "classLoader", classloader);
        return otherConfig;
    }
}
